var prefix = ctx + "business/memberInfo"

$(function() {
	var columns = [{
            checkbox: true
        },
		{
			field : 'id', 
			title : '主键Id' 
		},
		{
			field : 'name', 
			title : '会员名' 
		},
		{
			field : 'level', 
			title : '等级' 
		},
		{
			field : 'joinDate', 
			title : '入会日期' ,
			formatter: function (value, row, index) {
		        return formatDate(value)
		    }
		},
		{
			field : 'roomNo', 
			title : '房号' 
		},
		{
			field : 'totalPrice', 
			title : '总价' 
		},
		{
			field : 'registerNo', 
			title : '登记表号' 
		},
		{
			field : 'adviser', 
			title : '置业顾问' 
		},
		{
			field : 'manager', 
			title : '经理' 
		},
		{
			field : 'point', 
			title : '积分' 
		},
		{
			field : 'totalPoint', 
			title : '总积' 
		},
		{
			field : 'societyPoint', 
			title : '会分' 
		},
		{
			field : 'totalSocietyPoint', 
			title : '总会分' 
		},
		{
			field : 'message', 
			title : '信息' 
		},
		{
			field : 'visitingCard', 
			title : '名片' 
		},
		{
			field : 'resource', 
			title : '来源' 
		},
        {
            title: '操作',
            align: 'center',
            formatter: function(value, row, index) {
            	var actions = [];
				actions.push('<a class="btn btn-primary btn-sm ' + editFlag + '" href="#" title="编辑" mce_href="#" onclick="edit(\'' + row.id + '\')"><i class="fa fa-edit"></i></a> ');
				actions.push('<a class="btn btn-warning btn-sm ' + removeFlag + '" href="#" title="删除" onclick="remove(\'' + row.id + '\')"><i class="fa fa-remove"></i></a>');
				return actions.join('');
            }
        }];
	var url = prefix + "/list";
	$.initTable(columns, url);
});

/*会员-新增*/
function add() {
    var url = prefix + '/add';
    layer_showAuto("新增会员", url);
}

/*会员-修改*/
function edit(id) {
    var url = prefix + '/edit/' + id;
    layer_showAuto("修改会员", url);
}

// 单条删除
function remove(id) {
	$.modalConfirm("确定要删除选中会员吗？", function() {
		_ajax(prefix + "/remove/" + id, "", "post");
    })
}

// 批量删除
function batchRemove() {
	var rows = $.getSelections("id");
	if (rows.length == 0) {
		$.modalMsg("请选择要删除的数据", "warning");
		return;
	}
	$.modalConfirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
		_ajax(prefix + '/batchRemove', { "ids": rows }, "post");
	});
}


function formatDate(date) {
	  var d = new Date(date),
	    month = '' + (d.getMonth() + 1),
	    day = '' + d.getDate(),
	    year = d.getFullYear();
	 
	  if (month.length < 2) month = '0' + month;
	  if (day.length < 2) day = '0' + day;
	 
	  return [year, month, day].join('-');
	}
